package com.gzz.orchid.common.boot.mybatis.lambda;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * @author higmd
 */
public class GenericClass<T>{
    private T clazz;
    public GenericClass(T clazz){
        this.clazz = clazz;
    }
    public GenericClass(){

    }
    public Class<T> getGenericType() {
        Type type = getClass().getGenericSuperclass();
        ParameterizedType parameterizedType = (ParameterizedType) type;
        Type[] types = parameterizedType.getActualTypeArguments();
        if (types != null) {
            @SuppressWarnings("unchecked")
            Class<T> clazz = (Class<T>) types[0];
            return clazz;
        }
        throw  new IllegalStateException("无法获到泛型");
    }

    public static <T> GenericClass<T> builder(T clazz) {
        return new GenericClass<>(clazz);
    }
}
